﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Upfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //CommonFunction.CheckLimit(",");
    }
 
        protected void Button2_Click(object sender, EventArgs e)
    {
        if(FileUpload1.PostedFile!=null){
            string Url = Request.QueryString["FilePath"]+"/";
            string filename;//文件名字
            string hz;
            string newname;
            string imgtype = "gif|jpg|jpeg|bmp";
            filename=FileUpload1.FileName;
            //取后最
            int pos = filename.LastIndexOf(".");
            hz = filename.Substring((pos+1),filename.Length-pos-1).ToLower();

            if (filename.IndexOf(hz)<=0)
            {
                CommonFunction.ShowMessage("只支持－－－"+imgtype,2,"Upfile.aspx",true);               
            }
            newname = sjname() +"."+ hz;
            //保存图片
            string pathurl;
            //pathurl = Server.MapPath("~") + "\\"+Request.QueryString["FilePath"]+"\\" + newname;
			pathurl = Server.MapPath("~") + "\\"+Request.QueryString["FilePath"]+"\\" + newname;
            string kb = FileUpload1.FileContent.Length.ToString();
            
            FileUpload1.PostedFile.SaveAs(pathurl);
            if (!string.IsNullOrEmpty(Request.QueryString["Add"]))
            {
                Response.Write("<script>parent.document.form1." + Request.QueryString["Obj"] + ".value+='" + newname + "|';</script>");
            }
            else
            {
                Response.Write("<script>parent.document.form1." + Request.QueryString["Obj"] + ".value='" + newname + "';</script>");
            }
            //Response.Write("<script>parent.document.form1.imgUrl.value=parent.document.form1.imgUrl.value+'" + Url + newname + "';</script>");
              // FileUpload1.SaveAs(pathurl);
           

        }
    }
    /// <summary>
    /// 产生个随即名称

    /// </summary>
    /// <returns></returns>
    public string sjname() {

        string sj = null;
        sj = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.TimeOfDay.Hours.ToString() + DateTime.Now.TimeOfDay.Minutes.ToString() + DateTime.Now.TimeOfDay.Milliseconds.ToString();
        return sj;
    
    
    }
   
}

